#include <string.h>
#include <sys/socket.h>
#include <iostream>
#include <netinet/in.h>
#include <stdlib.h>

using namespace std;

static const int PORT = 50000;

int main(int argc, char** argv)
{
	int listen_fd = socket(AF_INET, SOCK_DGRAM, 0);

	struct sockaddr_in my_addr;
	my_addr.sin_family = AF_INET;
	my_addr.sin_port = htons(PORT);
	my_addr.sin_addr.s_addr = htonl(INADDR_ANY);

	int L = atoi(argv[1]);

	bind(listen_fd, (struct sockaddr*)&my_addr, sizeof(my_addr));
	char buff[1024];
	int res;
	int count = 0;
	while(true)
	{
		res = recvfrom(listen_fd, buff, sizeof(buff), 0, NULL, NULL);
		if(res > 0)
			count++;

		if(count > L)
		{
			cout<<L<<endl;
			count = 0;
		}
	}
}
